/*
 * JOY电子商务网运营事业部
 * 中国移动通信集团设计院有限公司
 * B2BJOY.COM  OPERATION  DIVISION
 * China Mobile Group Design Institute Co., Ltd
 */

package com.uhaou.system.action;

import java.util.HashMap;
import java.util.Hashtable;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

import cn.org.rapid_framework.page.Page;
import cn.org.rapid_framework.web.scope.Flash;
import cn.org.rapid_framework.web.util.HttpUtils; 

import com.uhaou.common.base.BaseStruts2Action;
import com.uhaou.common.util.EasyUIJsonUtil;
import com.uhaou.common.util.Json; 
import com.uhaou.system.model.*; 
import com.uhaou.system.service.*; 
import com.uhaou.system.vo.query.*; 

import com.opensymphony.xwork2.ModelDriven;
import com.opensymphony.xwork2.Preparable;

/**
 * @author  jiangcheng
 * @version 1.0
 * @since 1.0
 */


public class SysRoleAssignAction extends BaseStruts2Action implements Preparable,ModelDriven{
	//默认多列排序,example: username desc,createTime asc
	protected static final String DEFAULT_SORT_COLUMNS = null; 
	
	//forward paths
	protected static final String QUERY_JSP = "/system/role/SysRoleAssign/query.jsp";
	protected static final String LIST_JSP= "/system/role/SysRoleAssign/list.jsp";
	protected static final String CREATE_JSP = "/system/role/SysRoleAssign/create.jsp";
	protected static final String EDIT_JSP = "/system/role/SysRoleAssign/edit.jsp";
	protected static final String SHOW_JSP = "/system/role/SysRoleAssign/show.jsp";
	//redirect paths,startWith: !
	protected static final String LIST_ACTION = "!/system/role/SysRoleAssign/list.do";
	
	private ISysRoleAssignManager tsysRoleAssignManager;
	/*private ISysDeptManager tsysDeptManager;*/
	private SysRoleAssign tsysRoleAssign;
	java.lang.String id = null;
	private String[] items;
	private String param;
	
	public void setParam(String param){
		this.param = param;
	}

	public void prepare() throws Exception {
		if (isNullOrEmptyString(id)) {
			tsysRoleAssign = new SysRoleAssign();
		} else {
			tsysRoleAssign = (SysRoleAssign)tsysRoleAssignManager.getById(id);
		}
	}
	
	/** 增加setXXXX()方法,spring就可以通过autowire自动设置对象属性,注意大小写 */
	public void setSysRoleAssignManager(ISysRoleAssignManager manager) {
		this.tsysRoleAssignManager = manager;
	}	
//	public void setSysDeptManager(ISysDeptManager manager) {
//		this.tsysDeptManager = manager;
//	}
	public Object getModel() {
		return tsysRoleAssign;
	}
	
	public void setId(java.lang.String val) {
		this.id = val;
	}

	public void setItems(String[] items) {
		this.items = items;
	}
	
	/** 执行搜索 */
	public String list() {
		return LIST_JSP;
	}
	
	public String listAjax(){
		SysRoleAssignQuery query = newQuery(SysRoleAssignQuery.class,DEFAULT_SORT_COLUMNS);
		
		Page page = tsysRoleAssignManager.findPage(query);
//		savePage(page,query);
		Map map = new HashMap();
		map.put("total", page.getTotalCount());
		map.put("rows", page.getResult());
		return writeAjaxResponse(Json.toJson(map));
	}
	
	/** 查看对象*/
	public String show() {
		return SHOW_JSP;
	}
	
	/** 进入新增页面*/
	public String create() {
		return CREATE_JSP;
	}
	
	/** 保存新增对象 */
//	public String save() {
//		
//		//获得所有要分配角色的部门，如果不是部门则list为null
//		List<SysDept> list = null;
//		if(tsysRoleAssign!=null&&tsysRoleAssign.getObjType().equals("1")){
//			SysDept tsd = this.tsysDeptManager.getById(tsysRoleAssign.getObjId());
//			list = tsysDeptManager.getDeptnodeList(tsd.getDeptCode());
//		}
//		
//		//tsysRoleAssign 里的roleid 是多个roleid以“：”分隔的字符串
//		tsysRoleAssignManager.saveAlldept(tsysRoleAssign,list);
//		return writeAjaxResponse("1");
//	}
/*	*//**
	 * 保存对象，解决同一URL的权限控制zhanghao
	 * @return
	 *//*
	public String savebyuser(){
		return this.save();
	}*/
	/**
	 * 保存对象，解决同一URL的权限控制zhanghao
	 * @return
	 */
//	public String savebydept(){
//		return this.save();
//	}
	
	/**进入更新页面*/
	public String edit() {
		return EDIT_JSP;
	}
	
	/**保存更新对象*/
	public String update() {
		tsysRoleAssignManager.update(this.tsysRoleAssign);
		Flash.current().success(UPDATE_SUCCESS);
		return LIST_ACTION;
	}
	
	/**删除对象*/
	public String delete() {
		for(int i = 0; i < items.length; i++) {
			Hashtable params = HttpUtils.parseQueryString(items[i]);
			java.lang.String id = new java.lang.String((String)params.get("id"));
			tsysRoleAssignManager.removeById(id);
		}
		Flash.current().success(DELETE_SUCCESS);
		return LIST_ACTION;
	}

}
